<!--
 * @Author: 李惠婵 lihuichan@yxhyidc.com
 * @Date: 2022-07-04 09:33:01
 * @LastEditors: 李惠婵 lihuichan@yxhyidc.com
 * @LastEditTime: 2022-07-13 18:01:12
 * @FilePath: \robot-webd:\project\rural-revitalization-web\src\views\system\tennatDataSource\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div class="app-container">
        <!--查询数据-->
        <div class="SearchTop">
            <el-form :model="queryParams" ref="queryRef" :inline="true">
                <el-form-item label="租户Id" prop="tenantId">
                    <el-input v-model="queryParams.tenantId" placeholder="请输入租户Id" clearable
                        @keyup.enter="handleQuery" />
                </el-form-item>
                <el-form-item label="模块名" prop="moduleName">
                    <el-input v-model="queryParams.moduleName" placeholder="请输入模块名" clearable
                        @keyup.enter="handleQuery" />
                </el-form-item>
                <el-row class="searchBtn">
                    <el-col :span="8">
                        <el-form-item>
                            <el-button type="primary" icon="Search" @click="handleQuery"
                                v-hasPermi="['upms:DataSourceConfig:list']">查询
                            </el-button>
                            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item>
                            <el-button type="primary" plain icon="Plus" @click="handleAdd"
                                v-hasPermi="['upms:DataSourceConfig:edit']">
                                新增
                            </el-button>
                            <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete"
                                v-hasPermi="['upms:DataSourceConfig:remove']">删除
                            </el-button>
                        </el-form-item>
                    </el-col>

                </el-row>
            </el-form>
        </div>
        <!--表格数据-->
        <div class="tableList">
            <el-table :data="tableData" v-loading="loading" style="width: 100%" border class="table-container" stripe
                align="center" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" :align="center"> </el-table-column>
                <el-table-column label="序号" width="60" type="index" :align="center"> </el-table-column>
                <template v-for="(item, i) in tableHead" :key="i">
                    <el-table-column :prop="item.dataIndex" :label="item.title" show-overflow-tooltip :align="center">

                    </el-table-column>
                </template>
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template #default="scope">

                        <a @click="handleUpdate(scope.row)" title="编辑" v-hasPermi="['upms:DataSourceConfig:edit']">
                            <img src="../../../assets/images/manage/bianji.png" alt="" />

                        </a>

                        <a @click="handleDelete(scope.row)" title="删除" v-hasPermi="['upms:DataSourceConfig:remove']">
                            <img src="../../../assets/images/manage/shanchu.png" alt="" />
                        </a>
                    </template>
                </el-table-column>
            </el-table>
            <pagination v-show="total > 0" v-model:page="queryParams.pageNum" :total="total"
                v-model:limit="queryParams.pageSize" @pagination="getList" />
        </div>
        <addDataSource ref="addFrom" @refresh="getList"></addDataSource>
    </div>

</template>

<script setup>
import { dataSourceList, delDataSource } from '@/api/system/dataSource'
import addDataSource from './addDataSource'
const loading = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const { proxy } = getCurrentInstance();
const data = reactive({
    form: {},
    queryParams: {
        pageNum: 1,
        pageSize: 10,
        tenantId: undefined,
        moduleName: undefined,
    },
    tableHead: [
        {
            dataIndex: 'name',
            title: '配置名称',

        },
        {
            dataIndex: 'dbAliasKey',
            title: '数据库配置别名',

        },

        {
            dataIndex: 'tenantId_dictText',
            title: '租户',

        },
        {
            dataIndex: 'moduleName_dictText',
            title: '模块名',

        },
        {
            dataIndex: 'dbUseType_dictText',
            title: '数据库使用类型 ',

        },
        {
            dataIndex: 'masterSlave_dictText',
            title: '主从模式',

        },
        {
            dataIndex: 'dbNum',
            title: '集群数据库编号',

        },
        {
            dataIndex: 'privateDb_dictText',
            title: '是否私有库',

        },
    ],
    tableData: []
});
const { queryParams, form, tableHead, tableData } = toRefs(data);
/** 查询列表 */
function getList() {
    loading.value = true;
    dataSourceList(queryParams.value).then(response => {
        if (response.code == 200) {
            tableData.value = response.rows
            total.value = response.total;
            loading.value = false;
        }
    })
}
/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}
/** 重置按钮操作 */
function resetQuery() {
    date.value = '';
    proxy.resetForm("queryRef");
    handleQuery();
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
    ids.value = selection.map(item => item.id);
    single.value = selection.length != 1;
    multiple.value = !selection.length;
}
function handleAdd() {
    // visible.value = true;
    proxy.$refs["addFrom"].add();
}
function handleUpdate(row) {
    proxy.$refs["addFrom"].edit(row);
}
/** 删除按钮操作 */
function handleDelete(row) {
    const Ids = row.id || ids.value;
    proxy.$modal.confirm('是否确认删除此套餐？').then(function () {
        return delDataSource(Ids);
    }).then(() => {
        getList();
        proxy.$modal.msgSuccess("删除成功");
    }).catch(() => { });
}
getList()
</script>

<style scoped>
</style>

